<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template

require_once(dirname(__FILE__) . "/../controlHeader.php");				//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

include_once("impl/CelebrityImpl.php");
include_once("impl/CategoryImpl.php");

	
$celebrityImpl 	= new CelebrityImpl(DB_TAG_MM);
$oCatImpl 		= new CategoryImpl(DB_TAG_MM);


$error_message 	= '';

$name			= '';
$description	= '';
$status			= '1';
$isGroup		= '0';

if(isset($_POST['Submit'])){
	$name			= $_POST['name'];
	$description	= $_POST['description'];
	$status			= $_POST['status'];;
	
	$sex			= $_POST['sex'];
	$birthDate		= $_POST['birthDate'];
	
	$phone			= $_POST['phone'];
	$mobilePhone	= $_POST['mobilePhone'];

	$census			= $_POST['census'];
	$address		= $_POST['address'];

	$parentId		= $_POST['parentId'];
	$isGroup		= $_POST['isGroup'];

	$catIds			= $_POST['catIds'];// array

	if(!is_array($catIds))
		$error_message = 'category is required.';
		
	if(empty($error_message)){
		$dto = new CelebrityDto();
					
		$dto->name 			= $name;
		$dto->description	= $description;
		$dto->status		= $status;
		$dto->sex			= $sex;
		$dto->birthDate		= $birthDate;
		$dto->phone			= $phone;
		$dto->mobilePhone	= $mobilePhone;
		$dto->census		= $census;
		$dto->address		= $address;
	
		$dto->parentId		= $parentId;
		$dto->isGroup		= $isGroup;
			
		
		$id = $celebrityImpl->add($dto);
		if($id){
			$celebrityImpl->addCategories($id, $catIds);
			
			$error_message = 'add successfully.';
		}else 
			$error_message = 'add failure.';
	}
}

$catLeaf 		= $oCatImpl->getLeafList();
$celeGroups 	= $celebrityImpl->getGroupList();

$arrStatus 	= array('1' => 'Online', '0' => 'Offline');
$arrGroups 	= array('1' => 'Group', '0' => 'Personal');
$arrSexs 	= array('male' => 'Male', 'female' => 'Female', 'other' => 'Other');


/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrStatus', $arrStatus);
$smarty->assign('status', $status);

$smarty->assign('birthDate', $birthDate);
$smarty->assign('name', $name);

$smarty->assign('description', $description);

$smarty->assign('catLeaf', $catLeaf);
$smarty->assign('catIds', $catIds);

$smarty->assign('parentId', $parentId);

$smarty->assign('celeGroupId', $celeGroupId);
$smarty->assign('celeGroups', $celeGroups);

$smarty->assign('arrGroups', $arrGroups);
$smarty->assign('isGroup', $isGroup);

$smarty->assign('arrSexs', $arrSexs);
$smarty->assign('sex', $sex);

$smarty->display('listCelebrity_Add.htm');
?>
